<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0 auto;
        }
        .aa>li{
            float: left;
            margin-right:20px;
            list-style: none;
        }
    </style>
</head>
<body>
    <div id="app">
        <div><h3>天知道</h3></div>
        <div>
            <input placeholder="请输入所查询的城市" v-model="city" @keyup.enter="getWeather"/>
            <button @click="getWeather">查询</button>
            <ul class="aa">
                <li @click="cityWeather('北京')">北京</li>
                <li @click="cityWeather('上海')">上海</li>
                <li>广州</li>
                <li>深圳</li>
                <li>重庆</li>
            </ul>
        </div>
        <br/>
        <br/>
        <br/>
        <!-- 显示天气信息 -->
        <div> 
            <p>{{weather}}</p>
            <ul>
                <li v-for="item in weather.forecast">
                    {{item.date}}&nbsp;&nbsp;{{item.type}}&nbsp;&nbsp;
                    {{item.high}}-{{item.low}}&nbsp;&nbsp;{{item.fengxiang}}{{item.fengli}}
                </li>
            </ul>
        </div>
    </div>


    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        var app = new Vue({
            el:"#app",
            data:{
                city:"",
                weather:""
            },
            methods:{                
                getWeather:function(){
                    var that = this;
                    axios.get(`http://wthrcdn.etouch.cn/weather_mini?city=${that.city}`).then(function(response){
                        console.log(response.data.data);
                        that.weather = response.data.data;
                    });
                },
                // cityWeather:function(city){
                //     var that = this;
                //     axios.get(`http://wthrcdn.etouch.cn/weather_mini?city=${city}`).then(function(response){
                //         console.log(response.data.data);
                //         that.weather = response.data.data;
                //     });
                // },
                cityWeather:function(city){
                    this.city = city;
                    this.getWeather()
                }
            }
        })
    </script>
</body>
</html>